package com.travel.server.manager.impl.command.customer;

import com.travel.common.util.CollectionUtil;
import com.travel.server.manager.dto.request.EmptyRequest;
import com.travel.server.manager.dto.response.customer.QueryCustomerEnumResponse;
import com.travel.server.manager.dto.response.customer.QueryCustomerEnumResponse.CustomerEnumItem;
import com.travel.server.manager.impl.command.AbstractCommand;
import com.travel.server.manager.impl.dal.MemberGradeDal;
import com.travel.server.manager.impl.dal.TagDal;
import com.travel.server.manager.model.MemberGradeInfo;
import com.travel.server.manager.model.TagInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: LiZhenhui
 * @Date: 2018/11/9 18:10
 * @Desc:
 */
@Component
@Slf4j
public class QueryCustomerEnumCommand extends AbstractCommand<EmptyRequest, QueryCustomerEnumResponse> {

    @Autowired
    private MemberGradeDal memberGradeDal;

    @Autowired
    private TagDal tagDal;

    @Override
    protected void checkInput(EmptyRequest request) {

    }

    @Override
    public QueryCustomerEnumResponse handle(EmptyRequest request) {
        QueryCustomerEnumResponse response = new QueryCustomerEnumResponse();
        List<CustomerEnumItem> gradeList = new ArrayList<>();
        List<CustomerEnumItem> tagList = new ArrayList<>();

        List<MemberGradeInfo> memberGradeList = memberGradeDal.selectByExample(null);
        if(!CollectionUtil.isEmpty(memberGradeList)){
            for(MemberGradeInfo memberGradeInfo : memberGradeList){
                CustomerEnumItem item = new CustomerEnumItem();
                item.setId(memberGradeInfo.getId());
                item.setName(memberGradeInfo.getName());
                gradeList.add(item);
            }
        }

        List<TagInfo> infoList = tagDal.selectByExample(null);
        if(!CollectionUtil.isEmpty(infoList)){
            for(TagInfo tagInfo : infoList){
                CustomerEnumItem item = new CustomerEnumItem();
                item.setId(tagInfo.getId());
                item.setName(tagInfo.getName());
                tagList.add(item);
            }
        }

        response.setGradeList(gradeList);
        response.setTagList(tagList);
        return response;
    }
}
